package com.jindy.module.customer.service.impl;

import java.util.List;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.DateUtils;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.module.customer.domain.CustomerFollow;
import com.jindy.module.customer.mapper.CustomerFollowMapper;
import com.jindy.module.customer.service.ICustomerFollowService;
import com.jindy.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 客户跟进Service业务层处理
 *
 * @author ruoyi
 * @date 2022-09-20
 */
@Service
public class CustomerFollowServiceImpl implements ICustomerFollowService
{
    @Autowired
    private CustomerFollowMapper customerFollowMapper;
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询客户跟进
     *
     * @param id 客户跟进主键
     * @return 客户跟进
     */
    @Override
    public CustomerFollow selectCustomerFollowById(Long id)
    {
        return customerFollowMapper.selectCustomerFollowById(id);
    }

    /**
     * 查询客户跟进列表
     *
     * @param customerFollow 客户跟进
     * @return 客户跟进
     */
    @Override
    public List<CustomerFollow> selectCustomerFollowList(CustomerFollow customerFollow)
    {
        return customerFollowMapper.selectCustomerFollowList(customerFollow);
    }

    /**
     * 新增客户跟进
     *
     * @param customerFollow 客户跟进
     * @return 结果
     */
    @Override
    public int insertCustomerFollow(CustomerFollow customerFollow)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        customerFollow.setCreateId(sysUser.getUserId());
        customerFollow.setCreateBy(sysUser.getUserName());
        customerFollow.setCreateTime(DateUtils.getNowDate());
        customerFollow.setFollowUserId(sysUser.getUserId().toString());
        customerFollow.setFollowUserName(sysUser.getUserName());
        return customerFollowMapper.insertCustomerFollow(customerFollow);
    }

    /**
     * 修改客户跟进
     *
     * @param customerFollow 客户跟进
     * @return 结果
     */
    @Override
    public int updateCustomerFollow(CustomerFollow customerFollow)
    {
        customerFollow.setUpdateTime(DateUtils.getNowDate());
        return customerFollowMapper.updateCustomerFollow(customerFollow);
    }

    /**
     * 批量删除客户跟进
     *
     * @param ids 需要删除的客户跟进主键
     * @return 结果
     */
    @Override
    public int deleteCustomerFollowByIds(Long[] ids)
    {
        return customerFollowMapper.deleteCustomerFollowByIds(ids);
    }

    /**
     * 删除客户跟进信息
     *
     * @param id 客户跟进主键
     * @return 结果
     */
    @Override
    public int deleteCustomerFollowById(Long id)
    {
        return customerFollowMapper.deleteCustomerFollowById(id);
    }
}
